<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件加载</title>
</head>

<body>

</body>
<script>

    function loadScript(src) {
        return new Promise((resolve, reject) => {
            const script = document.createElement("script")
            script.src = src
            script.onload = () => {
                resolve(script)
            }
            script.onerror = reject
            document.body.appendChild(script)
        })
    }

    // 传统的加载，多层嵌套：
    // loadScript("a.js").then(script => {
    //     // console.log(script.src)
    //     loadScript("b.js").then(script => {
    //         // console.log(script.src)
    //         b()
    //     }
    //     )
    // })

    // Promise规范式开发,避免多层嵌套：
    loadScript("a.js")
        .then(
            script => {
                return loadScript("b.js")
            }
        )
        .then(
            script => {
                b()
            }
        )








</script>

</html>